from lib.webui_permission import *

class c73255:
    name = '产品管理员申请产品试用并下载-c73255'  # 测试用例名字
    # 记得更改登录用户为产品管理员，英文输入法
    # 初始化方法
    def setup(self):
        STEP(1, '登陆网站')
        driver = open_browser()
        productor_login(driver)

    # 清除方法
    def teardown(self):
        driver = get_global_webdriver()
        driver.quit()

    # 测试用例步骤
    def teststeps(self):
        # 获取webdriver对象 对应 已经登录好的浏览器
        driver = get_global_webdriver()
        # driver = webdriver.Firefox()
        extending_button = driver.find_element_by_id("hamburger-container")
        try:
            driver.find_element(By.CLASS_NAME, "el-tooltip")
            extending_button.click()
        except:
            print("左侧栏没有隐藏")

        STEP(2,"下载模板")
        download_module(driver)
        download_mod_list = check_file()
        CHECK_POINT("下载模板，检测下载文件名与数量", download_mod_list[1].endswith(".csv") and download_mod_list[0] == 1)

        STEP(3, "申请试用")
        commit_apply(driver)
        # time.sleep(3)

        STEP(4, "下载点击")
        # main ui button
        time.sleep(1)
        driver.find_element(By.CSS_SELECTOR,
                            "tr.el-table__row:nth-child(1) > td:nth-child(10) > div:nth-child(1) > button:nth-child(1) > span:nth-child(1)"
                             ).click()
        # inner button download
        time.sleep(3)
        driver.find_element(By.XPATH,
                            "/html/body/div[1]/div/div[2]/section/div[1]/div/div/div[5]/div/div[2]/div/div[1]/button/span"
                            ).click()
        download_a_file = check_file()
        CHECK_POINT("下载模板，检测下载文件名与数量", download_a_file[1].endswith(".iso") and download_a_file[0] == 1)

        # next button
        time.sleep(3)
        driver.find_element(By.XPATH,
                            "/html/body/div[1]/div/div[2]/section/div[1]/div/div/div[5]/div/div[2]/div/div[2]/button/span"
                            ).click()
        download_b_file = check_file()
        CHECK_POINT("下载模板，检测下载文件名与数量", download_b_file[1].endswith(".license") and download_b_file[0] == 1)

        # turn off
        time.sleep(3)
        INFO("CLOSE")
        driver.find_element(By.CSS_SELECTOR,
                            'div.el-dialog__footer:nth-child(3) > div:nth-child(1) > button:nth-child(1) > span:nth-child(1)'
                            ).click()
    # does it need to become a fun?

        time.sleep(4)
        product_word2 = driver.find_element(By.XPATH,
                                            "/html/body/div/div/div[1]/ul/div[1]/a/li/span"
                                            )
        product_word2.click()
        time.sleep(1)
        top_title0 = driver.find_element(By.XPATH,
                                         "/html/body/div/div/div[2]/div/div/div[2]/span/span/span[1]/span"
                                         ).text
        CHECK_POINT("上方第1个标题对应", "产品列表" == top_title0)

